<!--
 * @Description: 墙布变更单
 * 
 * @Author: Edan<Edan>
 * @Date: 2024-07-13 09:29:19
 * @FilePath: /yuxiuproweb/src/views/qb/change/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="销售单号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入销售单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="状态" prop="state">
        <el-select
          v-model="queryParams.state"
          placeholder="请选择状态"
          clearable
        >
          <el-option label="未审核" value="0" />
          <el-option label="已审核" value="1" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        > -->
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="qbChangeList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <template v-for="(i, index) in tableForm.item">
        <el-table-column
          :key="index"
          :prop="i.itemcode"
          :columnKey="i.itemcode"
          :label="i.itemname"
          :align="i.aligntype ? i.aligntype : 'center'"
          :min-width="i.minwidth"
          :show-overflow-tooltip="i.overflow ? true : false"
          :sortable="i.sortable ? true : false"
          v-if="i.displaymark ? true : false"
        >
          <template slot-scope="scope">
            <el-button
              v-if="i.itemcode == 'variationOrderId'"
              type="text"
              @click="handleDetail(scope.row)"
              >{{ scope.row[i.itemcode] }}</el-button
            >
            <div v-else-if="i.itemcode == 'state'">
              {{
                scope.row.state == "0"
                  ? "未审核"
                  : scope.row.state == "1"
                  ? "已审核"
                  : ""
              }}
            </div>

            <span v-else>{{ scope.row[i.itemcode] }}</span>
          </template>
        </el-table-column>
      </template>
      <!-- <el-table-column
        label="操作"
        align="center"
        width="120px"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            :disabled="scope.row.state === '1'"
            @click="handleExamine(scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情 -->
    <detail-view
      v-if="detail.show"
      :show.sync="detail.show"
      v-bind="detail"
      @update="getList()"
      @handleExamine="handleExamine"
    ></detail-view>
  </div>
</template>

<script>
import { getQbChangeList, updateQbChangeListItem } from "@/api/qb/change.js";
import DetailView from "./mods/detail.vue";
import { tableList } from "./mods/tablecolums.js";
import commonMix from "@/utils/mixins/common";
export default {
  name: "qbChange",
  components: {
    DetailView,
  },
  mixins: [commonMix],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 墙布表格数据
      qbChangeList: [],
      detail: {
        show: false,
        data: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        orderId: null,
        state: null,
        clientName: null,
      },
      //
      tableForm: tableList,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询高端定制列表 */
    getList() {
      this.loading = true;
      var queryParams = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        orderId: this.queryParams.orderId,
        clientName: this.queryParams.clientName,
        state: this.queryParams.state,
      };
      getQbChangeList(queryParams).then((res) => {
        this.qbChangeList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection);
      this.ids = selection.map((item) => item.variationOrderId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 查看明细操作 */
    handleDetail(row) {
      this.detail = {
        show: true,
        data: {
          ...row,
        },
      };
    },
    /** 审核按钮操作  */
    handleExamine(row) {
      this.$confirm("是否确定审核？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          updateQbChangeListItem({
            ...row,
            state: "1",
          }).then((res) => {
            this.getList();
          });
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      if (!this.ids.length) {
        this.$message.error("请勾选要导出的变更单");
        return;
      }
      var idsArr = [];
      for (var i = 0; i < this.ids.length; i++) {
        var item = this.ids[i];
        var obj = {
          variationOrderId: item,
        };
        idsArr.push(obj);
      }
      this.downloadExcel(
        "qb/variationOrder/export",
        idsArr,
        `变更单_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
